import { getStationNames, getTrainInfos } from "@/api/alarmInfo" 

export default {
  data() {
    return {
      alarmInfo: {
        station: '',  // 站场名称
        trainNo: '',  // 机车号
        startTime: new Date(new Date().getTime() - 3600 * 1000 * 24),
        endTime: new Date(new Date().getTime()),
        //workNo: '',   // 作业单号
        // page: 1,
        // limit: 10
      },
      listLoading: true,
      tableKey: 0,
      currentPage: 1,
      pageSize: 10,
      totalDataLength: 0,
      stationNameOptions: [],
      rcvTableData: [],
      tableHeight: 0
    }
  },
  created() {
    this.getAllStationNames()
    this.getAllTrainInfos()
  },
  mounted() {
    this.$nextTick(() => {
      // 根据浏览器高度设置初始高度
      this.tableHeight = window.innerHeight - this.$refs.refsTable.$el.offsetTop - 150
      // 监听浏览器高度变化，修改表格高度
      window.onresize = () => {
        this.tableHeight = window.innerHeight - this.$refs.refsTable.$el.offsetTop - 150
      }
    })
  },
  computed: {
  },
  watch: {
    startTime: function (newTime, oldTime) {
      if (!newTime) {
        this.startTime = new Date(new Date().getTime() - 3600 * 1000 * 24)
      }
    },
    endTime: function (newTime, oldTime) {
      if (!newTime) {
        this.endTime = new Date(new Date().getTime())
      }
    }
  },
  methods: {
    async getAllTrainInfos() {
      this.listLoading = true
      this.globalTableData = []
      // this.queryData.page = this.currentPage
      // this.queryData.limit = this.pageSize
      const res = await getTrainInfos(this.alarmInfo)
      if (res.msg) {
        this.$message.info(res.msg)
      } else {
        this.totalDataLength = res.data.length
        this.rcvTableData = res.data
      }
      this.listLoading = false
    },
    async getAllStationNames() {
      this.stationNameOptions = []
      const res = await getStationNames()
      if (res.msg) {
        this.$message.info(res.msg)
      } else {
        this.stationNameOptions = res.data
      }
    },
    reset() {
      this.alarmInfo.startTime = new Date(new Date().getTime() - 3600 * 1000 * 24)
      this.alarmInfo.endTime = new Date(new Date().getTime())
      this.alarmInfo.station = ''
      //this.alarmInfo.workNo = ''
      this.alarmInfo.trainNo = ''
      this.getAllTrainInfos()
    },
    search() {
      this.getAllTrainInfos()
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.getAllTrainInfos()
    },
    handleSizeChange: function (size) {
      this.pageSize = size
      this.getAllTrainInfos()
    }
  }
}
